package com.itheima.tlias84.mapper;

import com.itheima.tlias84.Po.InsertEmpParam;
import com.itheima.tlias84.Po.SelectEmpPageParam;
import com.itheima.tlias84.Po.UpdateEmpParam;
import com.itheima.tlias84.dto.ReportEmpGenderDTO;
import com.itheima.tlias84.dto.SelectEmpDTO;
import com.itheima.tlias84.entity.Emp;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Repository  @Mapper
 *都是标识Dao层的注解 (包不同)
 * @Mapper ->Mybatis提供
 * @Repository ->Spring提供
 */
//@Repository
@Mapper
public interface EmpMapper {
    /**
     * 查询所有员工
     */
    @Select("select id,username,password,name,gender,phone,job,salary,image,entry_date,dept_id,create_time,update_time from emp")
    List<SelectEmpDTO> selectAll();

    /**
     * 分页查询
     * @param param
     * @return
     */
    List<SelectEmpDTO> selectEmpByPage(@Param("p") SelectEmpPageParam param);

    /**
     * 批量删除
     */
    int batchDelete(@Param("ids") List<Integer> ids);

    int insertEmp(@Param("p") InsertEmpParam param);

    int updateEmp(@Param("p") UpdateEmpParam param);

    SelectEmpDTO selectEmpById(@Param("id") Integer id);

   @Select("select count(gender)as value,case gender when 1 then '男性员工'when 2 then '女性员工'end as name" +
           " from emp group by gender")
   List<ReportEmpGenderDTO> countEmpByGender();

   @Select("select job from emp")
   List<Integer>countEmpJob();

     @Select("select id,username,password,name from emp where username=#{username}")
    Emp selectEmpByUsername(@Param("username")String username);
}
